<template>
	<uni-loading v-if="loading"></uni-loading>
	<view class="body" v-else>
		<!--  列表  -->
		<template v-if="purInList && purInList.length > 0">
			<uni-swipe-action>
				<uni-swipe-action-item :left-options="options"  v-for="(item,index) in purInList" :key="index">
					<view class="panel" >
						<view class="panel_title">
							<view class="panel_title_left">{{ item.materialName }}</view>
						</view>
						<view class="panel_content">
							<view class="panel_content_row">
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">批次：</view>
									<view class="panel_content_row_item_value">{{ item.batchNo }}</view>
								</view>
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">仓位：</view>
									<view class="panel_content_row_item_value">{{ item.locationNo }}</view>
								</view>
							</view>
							
							<view class="panel_content_row">
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">规格：</view>
									<view class="panel_content_row_item_value">{{ item.materialSpec }}</view>
								</view>
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">单位：</view>
									<view class="panel_content_row_item_value">{{ item.unit }}</view>
								</view>
							</view>
							
							<view class="panel_content_row">
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">重量：</view>
									<view class="panel_content_row_item_value">{{ item.count }}{{ item.unit }}</view>
								</view>
								<!-- <view class="panel_content_row_item">
									<view class="panel_content_row_item_title">剩余：</view>
									<view class="panel_content_row_item_value">
										{{ item.nowColCount - item.count }}{{ item.unit }}</view>
								</view> -->
								<!-- <view class="panel_content_row_item">
									<view class="panel_content_row_item_title">总重：</view>
									<view class="panel_content_row_item_value">{{ item.nowColCount }}{{ item.unit }}</view>
								</view> -->
							</view>
						</view>
						<template>
							<view class="panel_content_row" >
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">退货数量：</view>
									<view class="panel_content_row_item_value" style="padding-right: 20rpx;">
										<view class="panel_content_row_item_value_input">
											<input type="digit" v-model="item.returnCount" placeholder="请输入退货数量"
												placeholder-class="input-placeholder"
												 />
										</view>
									</view>
								</view>
							</view>
						</template>
						<view class="flex-list-btn">
							<view  class="flex-list-btn-item"
								@click="handleTemporaryDelete(item)">
								删除
							</view>
							
						</view>
					</view>
				</uni-swipe-action-item>
			</uni-swipe-action>
		</template>
		<uni-empty-info v-else label="暂无物料信息"></uni-empty-info>
		<!--  底部按钮  -->
		<view class="footerPanel">
			<view class="footerPanel_body">
				
				<button @click="handleOutPur" class="footerBtn save"><i
						class="iconfont icon-duihao btn_icon"></i>生成退货单
				</button>
				<button @click="handleScanCode" class="footerBtn scan" type="primary"><i
						class="iconfont icon-saomiao btn_icon"></i>扫码
				</button>
			</view>
		</view>
		<PurInPopup ref="purInPopupRef" @success="taskScanningScuess"></PurInPopup>

	</view>
</template>
<script>
import PurInPopup from "../../components/popup/purInPopup.vue"
import uniLoading from "../../vBase/components/uni-loading/uni-loading"
	export default {
		components: {
			PurInPopup,
			uniLoading,
		},
		data() {
			return {
				loading: false,
				purInList: [],//列表数据
			}
		},
		async onLoad() {
			this.initData()
		},
		methods: {
			//生成退货单
			async handleOutPur(){
				let self = this
				uni.showModal({
					title:"提示",
					content: "是否生成退货单",
					success(res) {
						if (res.confirm){
							self.$api.addPurReturn({
								purList : self.purInList
							}).then(res => {
								if (res.res){
									uni.showToast({
										title:'操作成功',
										icon:'none'
									})
									self.initData()
								}
							})
						}
					}
				})
				
				
			},
			/**
			 * 删除不需要的列
			 */
			handleTemporaryDelete(item){
				let self = this
				uni.showModal({
					title:"提示",
					content: "是否确定删除",
					success:() => {
						self.purInList = self.purInList.filter(i => i !== item)
					}
				})
				
			},
			/** 初始化数据 */
			initData() {
				this.purInList = []
			},
		
			/** 扫码 */
			async handleScanCode() {
				this.$refs.purInPopupRef.open();
			},
			/**
			 * 扫码成功
			 * @param {Object} e
			 */
			async taskScanningScuess(e) {
				try{
					let res = await this.$api.getPurInByBillNo({
						billNo : e
					});
					if (!res) return;
					this.purInList = res.data
					
				} finally{
					this.loading = false;
				}
				
			},

			/**
			 * 下拉刷新数据
			 */
			onPullDownRefresh() {
				this.initData()
			},

			/** 上滑加载 */
			onReachBottom() {
				if (!this.pageConfig.bottomEnd) {
					this.pageConfig.pageIndex++
					this.pageConfig.bottomLoading = true
					this.getPurchaseList();
				}
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import "../../static/css/common";
	.panel{
		margin-top: 5px;
	}
	.panel_content_row_item_title{
		display: inline-block;
		float: left;
		margin-top: 5px;
	}
	.panel_content_row_item_value_input{
		display: inline-block;
		float: left;
		margin-top: 5px;
	}
	
</style>
